using System;
using CosyTrade.Core;
using CosyTrade.Organization;
using CosyTrade.Security;

namespace CosyTrade.UI
{
    [Addin("SystemStatCenter")]
    public class SystemStatCenter : AddinBase, ISystemStatCenter
    {
        private SystemStat sysStat;

        public SystemStat CreateSystemStat(Company loginCompany, Employee employee, User loginRole)
        {
            if (loginCompany == null) throw new ArgumentNullException("loginCompany");
            if (employee == null) throw new ArgumentNullException("employee");
            if (loginRole == null) throw new ArgumentNullException("loginRole");

            if (sysStat != null) Checkout();
            sysStat = new SystemStat(loginCompany, employee, loginRole);
            return GetSystemStat();
        }

        public SystemStat GetSystemStat()
        {
            if (sysStat == null) throw new Exception("SystemStat is Empty");
            return sysStat;
        }

        public void Checkout()
        {
            sysStat = null;
        }
    }
}